#include "qsqlrelationaltablemodelwithreconnection.h"
#include "db/dbconnection.h"
#include <QSqlError>
#include <QDebug>

bool QSqlRelationalTableModelWithReconnection::select()
{
    bool result = QSqlRelationalTableModel::select();
    if(result)
        return result;

    QString err = this->lastError().text();
    qDebug() << err;

    //try to reconnect
    QSharedPointer<DbConnection> db = DbConnection::instance();
    db->getDb().close();
    db->getDb().open();
    return QSqlRelationalTableModel::select();
}
